package com.xiaoma.controller;

import com.xiaoma.dao.ESDao;
import entity.Goods;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import utils.R;

import java.util.List;


/**
 * @Author: xiaoma
 * @Date: 2021/7/8 15:05
 * @description:
 */
@RestController
@RequestMapping("/search")
@Slf4j
public class ESController {
    @Autowired
    private ESDao esDao;

    @PostMapping("/product")
    public R productGoods(@RequestBody Goods goods) {
//        goods = new Goods(1,
//                "零基础学Java（全彩版）赠小白实战手册、练习题、纸质挂图/电子版魔卡 零基础自学编程的入门图书，由浅入深，详解Java语言的编程思想和核心技术，配同步视频教程和源代码，海量资源免费赠送团购热线010-89111488"
//                , "//img11.360buyimg.com/n1/s200x200_jfs/t1/143496/27/13717/281565/5fa79b07E02992451/f7454b996cc79bc7.jpg"
//                , "60.80", 1, 1, null);
        return esDao.productGoods(goods)?R.ok():R.error();
    }
    @GetMapping("/queryProductGoodsInEs/{keyword}")
    public R  queryProductGoodsInEs(@PathVariable String keyword){
        List<Goods> list = esDao.SearchGoodsByKeyword(keyword);
        return R.ok().put("data",list);
    }
}
